<?php


namespace app\login\model;


use app\api\service\Token;
use app\lib\exception\MysqlErrorException;
use think\Model;
use think\model\Pivot;

class Sign extends Model
{
    public function account()
    {
        return $this->belongsTo('Account', 'user_id', 'id');
    }

    public function getHostDAttr($value, $data)
    {
        if($value == '' || $value == null){
            return $value;
        }else{
            $name = Token::getRedisTokenName();
            return $value.'/'.$name.'/'.$data['sign'];
        }
    }

    public function getHostFAttr($value, $data)
    {
        if($value == '' || $value == null){
            return $value;
        }else{
            $name = Token::getRedisTokenName();
            return $value.'/'.$name.'/'.$data['sign'];
        }
    }

    # 删除一条sign记录
    public function delOne($id)
    {
        $model = self::where('sign_id', '=', $id)
            ->find();
        $sign = $model->sign;
        $model->delete();
        return $sign;
    }

    # 查找sign状态为1的所有列
    public function findSignStatus($id)
    {
        $arr = self::where('user_id', '=', $id)
            ->where('status', '=', 1)
            ->column('sign');
        return $arr;
    }
}